//
//  YPBuzTabBar_vc.swift
//  YPSwift
//
//  Created by ogawa on 2020/5/25.
//  Copyright © 2020 ogawa. All rights reserved.
//

import UIKit

class YPBuzTabBar_vc: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        tabBar.isTranslucent = false
        
//        UITabBarItem.appearance()
//        .setTitleTextAttributes(
//            [NSAttributedString.Key.font: UIFont(name: "Didot", size: 10)!],
//        for: .normal)

//        themeService.rx
//        .bind({ $0.primaryDark }, to: tabBar.rx.barTintColor)
//        .disposed(by: rx.disposeBag)
//        themeService.typeStream.delay(DispatchTimeInterval.milliseconds(50), scheduler: MainScheduler.instance)
//            .subscribe(onNext: { (theme) in
//                switch theme {
//                case .light(let color), .dark(let color):
//                    self.changeSelectedColor(color.color, iconSelectedColor: color.color)
//                }
//            }).disposed(by: rx.disposeBag)
        
        /// 首页
        let onePageVC = YPBuzHomePage_vc()
        addChildViewController(onePageVC,
                               title: "首页",
                               image: UIImage(named: "yp_m_img_home_tab_n"),
                               selectedImage: UIImage(named: "yp_m_img_home_tab_s"))


        /// 分类
        let classVC = YPBuzCategoryPage_vc()
        addChildViewController(classVC,
                               title: "分类",
                               image: UIImage(named: "yp_m_img_category_tab_n"),
                               selectedImage: UIImage(named: "yp_m_img_category_tab_s"))


        /// 发现
        let bookVC = YPBuzDiscoveryPage_vc()
        addChildViewController(bookVC,
                               title: "发现",
                               image: UIImage(named: "yp_m_img_discovery_tab_n"),
                               selectedImage: UIImage(named: "yp_m_img_discovery_tab_s"))
        
        
        /// 我的
        let mineVC = YPBuzMePage_vc()
        addChildViewController(mineVC,
                               title: "我的",
                               image: UIImage(named: "yp_m_img_me_tab_n"),
                               selectedImage: UIImage(named: "yp_m_img_me_tab_s"))
    }
    
    func addChildViewController(_ childController: UIViewController, title:String?, image:UIImage? ,selectedImage:UIImage?) {
        
        childController.title = title
        childController.tabBarItem = UITabBarItem(title: title,
                                                  image: image?.withRenderingMode(.alwaysOriginal),
                                                  selectedImage: selectedImage?.withRenderingMode(.alwaysOriginal))
        
        if UIDevice.current.userInterfaceIdiom == .phone {
            childController.tabBarItem.imageInsets = UIEdgeInsets(top: 6, left: 0, bottom: -6, right: 0)
        }
        
        addChild(YPCoreBaseNav_vc(rootViewController: childController))
    }
    
}

extension YPBuzTabBar_vc {
    override var preferredStatusBarStyle: UIStatusBarStyle {
        guard let select = selectedViewController else { return .lightContent }
        return select.preferredStatusBarStyle
    }
}
